package com.hecate.common.exception;

import com.hecate.common.response.HecateResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理器
 *
 * @author 黄星星
 * @date 2020-12-12
 */
@RestControllerAdvice
public class HecateGlobalExceptionHanlder {

    private static final Logger log = LoggerFactory.getLogger(HecateGlobalExceptionHanlder.class);

    /**
     * 处理自定义异常
     * @param hecateBusinessException
     * @return
     */
    @ExceptionHandler(value = HecateBusinessException.class)
    public HecateResponse biExceptionHanlder(HecateBusinessException hecateBusinessException){
        System.out.println("ddddddd");
        log.error("******************* 全局异常处理器:{}, e:{}", hecateBusinessException.getMessage(), hecateBusinessException);
        return HecateResponse.ERROR(hecateBusinessException.getMessage());
    }


    /**
     * 其他异常
     * @param exception
     * @return
     */
    @ExceptionHandler(value = Exception.class)
    public HecateResponse biExceptionHanlder(Exception exception){
        log.error("******************* 全局异常处理器:{}, e:{}", exception.getMessage(), exception);
        return HecateResponse.ERROR(exception.getMessage());
    }
}
